package com.wanjia.estate.pojo.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.Period;

@Schema(title ="权利人信息")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Details implements Serializable {
    private String idcardno;
    private String name;


    public Integer calculateYear() {
        try {
            //获取户口部的出生日期
            String yearAge = idcardno.substring(6, 10);
            String monthAge = idcardno.substring(10, 12);
            String dateAge = idcardno.substring(12, 14);
            String strBirthday = yearAge + "-" + monthAge + "-" + dateAge;
            LocalDate birthday = LocalDate.parse(strBirthday);
            //获取现在日期
            LocalDate now = LocalDate.now();
            Period period = Period.between(birthday, now);
            //得到现在年龄
            return period.getYears();
        } catch (Exception e) {
            throw new RuntimeException("计算年龄异常", e);
        }
    }
}
